<?php

/**
 * @author Watanabex
 * @copyright 2010
 * clase para el manejo de videos
 */

class Videos{
	public function addVideo($link, $tipo, $titulo){
		$video_number =NULL;
		$arrTipo = array();
		
		if(strstr($link, 'v=')){
			$arrTipo = explode('v=', $link);
			$varVid = explode('&', $arrTipo[1]);
			$video_number = $varVid[0];
		}else{
			$arrTipo = explode('/', $link);
			$video_number = $arrTipo[3];
		}
		
		
		$titulo = htmlentities($titulo,ENT_COMPAT, 'UTF-8');
		
		$SQL = "INSERT INTO videos (link, video_number, tipo, fechaPublicacion, titulo) VALUES ('".$link."', '".$video_number."', '".$tipo."', '".date('Y-m-d H:i:s')."', '".$titulo."')";
		$Q = mysql_query($SQL) or die(mysql_error());		
	}	
	
	public function getUltimoVideo(){
		$SQL = "SELECT * FROM videos ORDER BY fechaPublicacion DESC, tipo DESC LIMIT 1";
		$Q = mysql_query($SQL) or die(mysql_error());
		$row = mysql_fetch_array($Q);
		
		return $row;
	}
	
	public function getSexyNota(){
		$SQL = "SELECT * FROM videos WHERE tipo='sexynotas' ORDER BY fechaPublicacion DESC LIMIT 1";
		$Q = mysql_query($SQL) or die(mysql_error());
		$row = mysql_fetch_array($Q);
		
		return $row;
	}

	public function getTop10() {
		$SQL = "SELECT id, titulo, link, video_number FROM videos WHERE status='A' ORDER BY fechaPublicacion DESC, id DESC LIMIT 10";

		$q = mysql_query($SQL) or die(mysql_error());

		$arrVideo = array();
		$i = 0;

		while ($row = mysql_fetch_array($q)) {
			$arrVideo[$i]['id'] = $row['id'];
			$arrVideo[$i]['titulo'] = $row['titulo'];
			$arrVideo[$i]['link'] = $row['link'];
			$arrVideo[$i]['video_number'] = $row['video_number'];
			$i++;
		}

		return $arrVideo;
	}

    public function delVideo($id) {
        $SQL = "UPDATE videos SET status='S' WHERE id = ".$id;

        $q = mysql_query($SQL) or die(mysql_error());
    }
}